#pragma once
#include <vector>
#include "Params.h"
#include "BaseState.h"
#include "Model.h"
#include <string>

class Region;
class Team;
class Ball;
class Goal;

/*
	GameState it's the game itself.
	It's the owner of the world (pitch and 'stadium'), teams and ball.
	It's the controller of the physics updates (1/60sec) too.
*/

class GameState : public BaseState
{
public:
	GameState();
	~GameState(void);

	//GETTERS
	Region* const	Pitch()const{ return m_pitch; }
	Model* const	GetPitchModel()const{ return m_pitchModel; }
	float const		GetUpdateTime()const{ return m_updateTime; }
	Region* const	GetRegion(const int id);
	Goal* const		RedGoal()const{	return m_redGoal; }
	Goal* const		BlueGoal()const{ return m_blueGoal; }
	Team* const		GetRedTeam()const{ return m_redTeam; }
	Team* const		GetBlueTeam()const{ return m_bluTeam; }
	bool			IsOn()const{ return m_playing; }
	bool			IsPaused()const{ return m_paused; }

	//SETTERS
	inline void		SetPaused(bool p = true){ m_paused = p; }
	inline void		AddPauseTime(float pTime){ m_pausedTime += pTime; }

	inline void		StartGame() { PrepareForKickOff(); } 
	
	void			OnDraw(sf::RenderWindow&);
	void			OnIdle(const sf::Input&);
	
private:
	bool					m_paused;			//game is paused
	bool					m_playing;			//playing or waiting kickoff, corner etc etc

	float					m_updateTime;
	float					m_lastUpdateTime;

	bool					m_updateEnabled;

	std::string				m_messageToDisplay;
	float					m_messageTime;
	float					m_gameTime;
	float					m_waitedTime;
	float					m_pausedTime;

	sf::Clock				m_clock;

	//Playable Area and it's model
	Region*					m_pitch;
	Model*					m_pitchModel;

	//Subregions of the playable area
	std::vector<Region*>	m_regions;

	//Special Subregions, like kickoff spot..corner kick spots.
	std::vector<Region*>	m_specialRegions;

	//Goal Areas
	Goal*					m_redGoal;
	Goal*					m_blueGoal;

	//out teams
	Team*					m_redTeam;
	Team*					m_bluTeam;
	
	//the ball
	Ball*					m_ball;

	//GUI vars
	sf::Text				m_guiRName;
	sf::Text				m_guiScore;
	sf::Text				m_guiBName;
	sf::Text				m_guiGameTime;
	sf::Vector2f			m_guiRadarOffset;
	sf::Image				m_guiRadarImage;
	sf::Sprite				m_guiRadar;
	short					m_currentCamera;

	void					CreateRegions(int rows, int cols);
	void					PrepareForKickOff(Params::TeamColor color = Params::blue);
	void					CheckForOutOrGoal();
	bool					IsGoal(Goal* goal, Params::TeamColor color);
	void					ManageGeneralInput(const sf::Input&);

	void					DrawMatchInfo(sf::RenderWindow&);
	void					DrawRadar(sf::RenderWindow& window);
	
};
